package com.rx.mgt.dao;

import com.rx.mgt.dao.base.ManagementHibernateDaoBase;
import com.rx.mgt.domain.Spam;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

/**
 * Created by zxj on 2017/5/31.
 */
@SuppressWarnings("JpaQlInspection")
@Repository
public class SpamDao extends ManagementHibernateDaoBase<Spam,Long> {

    public Spam getSpanByDomain(String domain) {
        String hql = " from Spam s where 1=1";
        if(StringUtils.isNotBlank(domain)){
            hql +=" and s.domain=:domain";
        }
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        query.setParameter("domain",domain);
        return (Spam) query.uniqueResult();
    }

    public void deleteByDomain(String domain) {
        String  hql = " delete from Spam s where s.domain=:domain";
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        query.setParameter("domain",domain);
        query.executeUpdate();
    }
}
